from php4dvd.pages.page import Page
from selenium.webdriver.common.by import By

class HomePage(Page):

    @property
    def add_movie_button(self):
        return self.driver.find_element_by_css_selector ("img[title=\"Add movie\"]")

    @property
    def search_input_field(self):
        return self.driver.find_element_by_id("q")

    @property
    def is_this_page(self):
        return self.is_element_visible((By.CSS_SELECTOR, "img[title=\"Add movie\"]"))

    def find_movies(self):
        return  self.driver.find_elements_by_css_selector("div.movie_box")

    def go_first_movie_on_the_page(self):
        movies = self.find_movies()
        filmId = movies[0].get_attribute("id")
        return self.driver.find_element_by_css_selector("#" + filmId + "> div.movie_cover > div.nocover").click()
        return filmId

